/****************************************************************************
** @brief
****************************************************************************/

#ifndef CARD_H
#define CARD_H

#include <QObject>

class QSerialPort;

class AbstractCard : public QObject
{
    Q_OBJECT

public:
    ///
    /// \brief The CardType enum
    ///
    enum CardType {
        kAnyue,          /* 安悦卡 */
        kThaisen,        /* 钛昕卡 */
        KYunkuaichong,   /* 云快充卡 */
        KThaisenAndYunkuaichong, /* 钛昕和云快充的混合卡 */
    };

    ///
    /// \brief The ReaderType enum
    ///
    enum ReaderType {
        KPuyue,          /* 普阅读卡器 */
        KZlg,            /* ZLG 读卡器 */
    };

    ///
    /// \brief The CardState enum
    ///
    enum CardState {
        KCardDown,       /* 掉电状态（属于正常状态） */
        kCardIdle,       /* 闲置状态 */
        kCardReady,      /* 准备状态 */
        kCardActivation, /* 激活状态 */
        kCardFinish,     /* 结束（完成）状态 */
        KCardOffIdle,    /* 离场状态 */
        KCardOffline,    /* 离线状态（属于异常状态） */
    };

    explicit AbstractCard(QObject *parent = nullptr);
    virtual ~AbstractCard();

    ///
    /// \brief InitState
    ///
    void InitState()
    {
        card_state_ = kCardIdle;
    }

    CardState card_state() const
    {
        return card_state_;
    }

    void set_card_state(CardState state)
    {
        card_state_ = state;
    }

    ReaderType reader_type() const
    {
        return reader_type_;
    }

    CardType card_type() const
    {
        return card_type_;
    }

    QByteArray uid() const
    {
        return uid_;
    }

    qint32 uid_len() const
    {
        return uid_len_;
    }

    QByteArray card_number() const
    {
        return card_number_;
    }

    qint32 card_num_len() const
    {
        return card_num_len_;
    }

    ///
    /// \brief TestSerial
    ///
    virtual void TestSerial() = 0;

protected:
    QSerialPort *serialport_;

    CardType card_type_;
    ReaderType reader_type_;
    CardState card_state_;

    QByteArray uid_;
    qint32 uid_len_;
    QByteArray card_number_;
    qint32 card_num_len_;

private:

signals:
    void HandleCardNumber(QByteArray& card_number);

public slots:
    ///
    /// \brief SearchCard
    ///
    virtual void SearchCard() = 0;

private slots:

};

#endif // CARD_H
